namespace SilverSea.LPRProcessing
{
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    public static class Untils
    {
        public static Bitmap CropImage(Image img, Rectangle cropArea)
        {
            try
            {
                Bitmap bitmap = new Bitmap(img);
                return bitmap.Clone(cropArea, bitmap.PixelFormat);
            }
            catch
            {
            }
            return null;
        }

        public static Bitmap ResizeImage(Image imgToResize, Size size)
        {
            try
            {
                int width = imgToResize.Width;
                int height = imgToResize.Height;
                float num3 = 0f;
                float num4 = 0f;
                float num5 = 0f;
                num4 = ((float) size.Width) / ((float) width);
                num5 = ((float) size.Height) / ((float) height);
                if (num5 < num4)
                {
                    num3 = num5;
                }
                else
                {
                    num3 = num4;
                }
                int num6 = (int) (width * num3);
                int num7 = (int) (height * num3);
                Bitmap image = new Bitmap(num6, num7);
                Graphics graphics = Graphics.FromImage(image);
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.DrawImage(imgToResize, 0, 0, num6, num7);
                graphics.Dispose();
                return image;
            }
            catch
            {
            }
            return null;
        }
    }
}

